if SERVER then

	AddCSLuaFile( "shared.lua" )
	SWEP.Weight				= 5
	SWEP.HoldType			= "grenade"
	SWEP.AutoSwitchTo		= false
	SWEP.AutoSwitchFrom		= false


end

if CLIENT then

	SWEP.DrawAmmo			= true
	SWEP.DrawCrosshair		= true
	SWEP.ViewModelFOV		= 80
	SWEP.ViewModelFlip		= true
	SWEP.CSMuzzleFlashes	= false

	SWEP.Slot				= 4
	SWEP.SlotPos			= 10
	
	SWEP.PrintName			= "Chicken Egg"	
	SWEP.Author				= "Teta_Bonita"
	SWEP.Contact			= "Don't"
	SWEP.Purpose			= "A chicken dispenser"
	SWEP.Instructions		= "Hold primary fire to throw chickens."
	
	SWEP.WepSelectIcon		= surface.GetTextureID( "weapons/swep" )
	SWEP.BounceWeaponIcon   = true

end

SWEP.Spawnable				= false
SWEP.AdminSpawnable			= true

SWEP.ViewModel				= "models/weapons/v_chickeneggnade.mdl"
SWEP.WorldModel				= "models/weapons/w_chickeneggnade.mdl"

SWEP.Primary.Sound			= ""
SWEP.Primary.Damage			= 0
SWEP.Primary.NumShots		= 0
SWEP.Primary.Delay			= 0.5
SWEP.Primary.Cone			= 0
SWEP.Primary.Recoil			= 0

SWEP.Primary.ClipSize		= -1
SWEP.Primary.DefaultClip	= 10
SWEP.Primary.Automatic		= true
SWEP.Primary.Ammo			= "Grenade"

SWEP.Secondary.ClipSize		= -1
SWEP.Secondary.DefaultClip	= -1
SWEP.Secondary.Automatic	= false
SWEP.Secondary.Ammo			= "none"


function SWEP:Initialize()

	if SERVER then
		self:SetWeaponHoldType( self.HoldType )
	end
	
	self.Attacking = false
	
end


function SWEP:PrimaryAttack()

	if self:Ammo1() <= 0 then 
	
	 	self:SetNextPrimaryFire( CurTime() + 0.5 )
		self:SetNextSecondaryFire( CurTime() + 0.5 )

		self.Attacking = false
		
 		return 
		
 	end
	
	if not self.Attacking then
	
		self:SetNextPrimaryFire( CurTime() + 1 )
		self:SendWeaponAnim( ACT_VM_PULLPIN )
		
		self.Attacking = true

		return
		
	end
	
	self:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
	
	self:SendWeaponAnim( ACT_VM_THROW )
	self.Owner:SetAnimation( PLAYER_ATTACK1 )
	
	self:TakePrimaryAmmo( 1 )
	
	if not SERVER then return end
	
	local plrang = self.Owner:EyeAngles()
	local muzzlepos = self.Owner:GetShootPos() + plrang:Right() * 5 - plrang:Up() * 7
	local muzzleforward = ( util.TraceLine( util.GetPlayerTrace( self.Owner ) ).HitPos - muzzlepos ):GetNormalized()
	
	local egg = ents.Create( "sent_egg" )
	egg:SetPos( muzzlepos + muzzleforward * 5 )
	egg:SetAngles( ( muzzleforward + VectorRand() * 0.4 ):Angle() )
	egg:SetOwner( self.Owner )
	egg:Spawn()
	egg:Activate()
	
	local eggphys = egg:GetPhysicsObject()
	if eggphys:IsValid() then
		eggphys:AddVelocity( muzzleforward * 500 )
		eggphys:AddAngleVelocity( VectorRand() * 200 )
	end
	
end


function SWEP:SecondaryAttack()


end


function SWEP:Think()

	if self.Attacking and self.Owner:KeyReleased( IN_ATTACK ) then
	
		if self:Ammo1() > 0 then 
			self:SendWeaponAnim( ACT_VM_DRAW )
		end
		
		self.Attacking = false
		
	end

end


function SWEP:Reload()

	return false
	
end


function SWEP:Deploy()

	self:SendWeaponAnim( ACT_VM_DRAW )
	
	return true

end
